package ex;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @author: knowno
 * @create: 2025-09-16 13:45
 * @Version 1.0
 **/
public class TestCollections {
    public static void main(String[] args) {
        //private Collections() {
        //    }
//        Arrays.sort(a, (Comparator) c);

        List list = Arrays.asList(100,2,3,4,5,6,-1,7,0);
        //只提供一个参数
        Collections.sort(list);
        System.out.println(list);
        //提供两个参数
        Collections.sort(list, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });
        System.out.println(list);

        System.out.println("****************************");
        List<Human> humans = Arrays.asList(new Human("a",28),new Human("b",19),new Human("c",20));
        Collections.sort(humans, new Comparator<Human>() {
            @Override
            public int compare(Human o1, Human o2) {
                return o1.getAge()-o2.getAge();
            }
        });
        System.out.println(humans);

        //如果是字符串呢? "123","2","5" =>想按照数字大小排序
        List<String> strings = Arrays.asList("123","2","5");
        Collections.sort(strings, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return Integer.parseInt(o1)-Integer.parseInt(o2);
            }
        });
        System.out.println(strings);



    }
}

class Human{
    private String name;
    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Human(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}